TyphoonFlow = function (scene) {
    var self = this;
    var parentScene = scene;
    
    // 台风参数
    var windSpeed = 1.0;
    var eyeRadius = 0.1;
    var spiralTightness = 2.0;
    var flowHeight = 1.0;
    var animationSpeed = 1.0;
    var opacity = 0.8;
    
    // 显示控制
    var showFlowLines = true;
    var showEyeStructure = true;
    var showParticles = false;
    
    // 三维对象组
    var flowLinesGroup;
    var eyeStructureGroup;
    var particlesGroup;
    var heatmapGroup;
    
    // 动画相关
    var time = 0;
    var flowLines = [];
    var particles = [];
    var heatmapMesh;
    
    // 热力图相关
    var showHeatmap = true;
    var heatmapResolution = 128;
    var heatmapSize = 3.0;
    
    // 台风中心位置
    var typhoonCenter = new THREE.Vector3(0, 0, 0);
    
    this.init = function() {
        // 初始化各个组件
        flowLinesGroup = new THREE.Group();
        eyeStructureGroup = new THREE.Group();
        particlesGroup = new THREE.Group();
        heatmapGroup = new THREE.Group();
        
        parentScene.add(flowLinesGroup);
        parentScene.add(eyeStructureGroup);
        parentScene.add(particlesGroup);
        parentScene.add(heatmapGroup);
        
        // 创建台风流场
        this.createFlowLines();
        this.createEyeStructure();
        this.createParticles();
        this.createHeatmap();
    };
    
    // 创建螺旋流线
    this.createFlowLines = function() {
        // 清空现有流线
        while(flowLinesGroup.children.length > 0) {
            flowLinesGroup.remove(flowLinesGroup.children[0]);
        }
        flowLines = [];
        
        var numSpirals = 12; // 螺旋线数量
        var pointsPerSpiral = 100; // 每条螺旋线的点数
        
        for (var i = 0; i < numSpirals; i++) {
            var angle = (i / numSpirals) * Math.PI * 2;
            var spiralPoints = [];
            
            for (var j = 0; j < pointsPerSpiral; j++) {
                var t = j / pointsPerSpiral;
                var radius = eyeRadius + t * 1.5; // 从台风眼向外扩展
                
                // 螺旋角度计算
                var spiralAngle = angle + t * spiralTightness * Math.PI * 2;
                
                // 计算位置
                var x = Math.cos(spiralAngle) * radius;
                var z = Math.sin(spiralAngle) * radius;
                
                // 高度变化 - 台风眼附近较低，外围较高
                var heightFactor = Math.min(1.0, radius / 0.5);
                var y = (Math.sin(t * Math.PI) * heightFactor * flowHeight) - 0.2;
                
                spiralPoints.push(new THREE.Vector3(x, y, z));
            }
            
            // 创建流线几何体
            var curve = new THREE.CatmullRomCurve3(spiralPoints);
            var geometry = new THREE.TubeGeometry(curve, pointsPerSpiral, 0.005, 8, false);
            
            // 创建材质 - 根据高度和距离中心的距离变化颜色
            var material = new THREE.MeshBasicMaterial({
                color: this.getFlowLineColor(i, numSpirals),
                transparent: true,
                opacity: opacity
            });
            
            var flowLine = new THREE.Mesh(geometry, material);
            flowLinesGroup.add(flowLine);
            flowLines.push({
                mesh: flowLine,
                originalPoints: spiralPoints,
                phase: i / numSpirals * Math.PI * 2
            });
        }
        
        // 添加更多层次的流线
        this.createVerticalFlowLines();
        this.createMultiLevelFlowLines();
        this.createRadialFlowLines();
    };
    
    // 创建垂直流线（表现台风的立体结构）
    this.createVerticalFlowLines = function() {
        var numVerticalLines = 12;
        var radius = eyeRadius * 1.5;
        
        for (var i = 0; i < numVerticalLines; i++) {
            var angle = (i / numVerticalLines) * Math.PI * 2;
            var x = Math.cos(angle) * radius;
            var z = Math.sin(angle) * radius;
            
            var verticalPoints = [];
            for (var j = 0; j <= 25; j++) {
                var y = (j / 25) * flowHeight - 0.2;
                // 添加轻微的螺旋扭曲
                var spiralOffset = Math.sin(y * 3) * 0.02;
                verticalPoints.push(new THREE.Vector3(
                    x + spiralOffset * Math.cos(angle + Math.PI/2),
                    y,
                    z + spiralOffset * Math.sin(angle + Math.PI/2)
                ));
            }
            
            var curve = new THREE.CatmullRomCurve3(verticalPoints);
            var geometry = new THREE.TubeGeometry(curve, 25, 0.003, 6, false);
            
            // 使用基于风速的颜色
            var windSpeed = this.getWindSpeedAtRadius(radius);
            var color = this.getWindSpeedColor(windSpeed, 2.0);
            
            var material = new THREE.MeshBasicMaterial({
                color: color,
                transparent: true,
                opacity: opacity * 0.7
            });
            
            var verticalLine = new THREE.Mesh(geometry, material);
            flowLinesGroup.add(verticalLine);
        }
    };
    
    // 创建多层次流线
    this.createMultiLevelFlowLines = function() {
        var numLevels = 5;
        
        for (var level = 0; level < numLevels; level++) {
            var levelHeight = (level / (numLevels - 1)) * flowHeight - 0.2;
            var levelRadius = eyeRadius + level * 0.2;
            var numLines = 8 + level * 2;
            
            for (var i = 0; i < numLines; i++) {
                var angle = (i / numLines) * Math.PI * 2 + level * 0.3;
                var levelPoints = [];
                
                for (var j = 0; j < 50; j++) {
                    var t = j / 50;
                    var radius = levelRadius + t * (1.0 - level * 0.1);
                    var spiralAngle = angle + t * spiralTightness * Math.PI;
                    
                    var x = Math.cos(spiralAngle) * radius;
                    var z = Math.sin(spiralAngle) * radius;
                    var y = levelHeight + Math.sin(t * Math.PI * 2) * 0.05;
                    
                    levelPoints.push(new THREE.Vector3(x, y, z));
                }
                
                var curve = new THREE.CatmullRomCurve3(levelPoints);
                var geometry = new THREE.TubeGeometry(curve, 50, 0.002, 4, false);
                
                // 层次化颜色
                var levelIntensity = level / (numLevels - 1);
                var color = this.getWindSpeedColor(levelIntensity * 2.0, 2.0);
                
                var material = new THREE.MeshBasicMaterial({
                    color: color,
                    transparent: true,
                    opacity: opacity * (0.3 + levelIntensity * 0.4)
                });
                
                var levelLine = new THREE.Mesh(geometry, material);
                flowLinesGroup.add(levelLine);
            }
        }
    };
    
    // 创建径向流线
    this.createRadialFlowLines = function() {
        var numRadialLines = 16;
        
        for (var i = 0; i < numRadialLines; i++) {
            var angle = (i / numRadialLines) * Math.PI * 2;
            var radialPoints = [];
            
            for (var j = 0; j <= 30; j++) {
                var t = j / 30;
                var radius = eyeRadius * 0.5 + t * 1.5;
                var height = Math.sin(t * Math.PI) * flowHeight * 0.8 - 0.1;
                
                // 添加径向扭曲
                var twistAngle = angle + t * 0.5;
                var x = Math.cos(twistAngle) * radius;
                var z = Math.sin(twistAngle) * radius;
                
                radialPoints.push(new THREE.Vector3(x, height, z));
            }
            
            var curve = new THREE.CatmullRomCurve3(radialPoints);
            var geometry = new THREE.TubeGeometry(curve, 30, 0.001, 4, false);
            
            var material = new THREE.MeshBasicMaterial({
                color: 0x88ccff,
                transparent: true,
                opacity: opacity * 0.4
            });
            
            var radialLine = new THREE.Mesh(geometry, material);
            flowLinesGroup.add(radialLine);
        }
    };
    
    // 创建台风眼结构
    this.createEyeStructure = function() {
        // 清空现有台风眼结构
        while(eyeStructureGroup.children.length > 0) {
            eyeStructureGroup.remove(eyeStructureGroup.children[0]);
        }
        
        // 台风眼壁
        var eyeWallGeometry = new THREE.CylinderGeometry(eyeRadius, eyeRadius * 1.2, flowHeight, 16, 1, true);
        var eyeWallMaterial = new THREE.MeshBasicMaterial({
            color: 0xff4444,
            transparent: true,
            opacity: 0.3,
            side: THREE.DoubleSide
        });
        var eyeWall = new THREE.Mesh(eyeWallGeometry, eyeWallMaterial);
        eyeWall.position.y = flowHeight / 2 - 0.2;
        eyeStructureGroup.add(eyeWall);
        
        // 台风眼底部的漩涡效果
        var vortexGeometry = new THREE.RingGeometry(0, eyeRadius, 32);
        var vortexMaterial = new THREE.MeshBasicMaterial({
            color: 0x8844ff,
            transparent: true,
            opacity: 0.5,
            side: THREE.DoubleSide
        });
        var vortex = new THREE.Mesh(vortexGeometry, vortexMaterial);
        vortex.rotation.x = -Math.PI / 2;
        vortex.position.y = -0.2;
        eyeStructureGroup.add(vortex);
        
        // 添加台风眼中心的上升气流指示
        this.createUpwardFlow();
    };
    
    // 创建上升气流
    this.createUpwardFlow = function() {
        var numUpwardLines = 6;
        
        for (var i = 0; i < numUpwardLines; i++) {
            var angle = (i / numUpwardLines) * Math.PI * 2;
            var radius = eyeRadius * 0.3;
            var x = Math.cos(angle) * radius;
            var z = Math.sin(angle) * radius;
            
            var upwardPoints = [];
            for (var j = 0; j <= 15; j++) {
                var y = (j / 15) * flowHeight * 1.5 - 0.2;
                var spiralRadius = radius * (1 - j / 15 * 0.5);
                var spiralAngle = angle + (j / 15) * Math.PI;
                
                upwardPoints.push(new THREE.Vector3(
                    Math.cos(spiralAngle) * spiralRadius,
                    y,
                    Math.sin(spiralAngle) * spiralRadius
                ));
            }
            
            var curve = new THREE.CatmullRomCurve3(upwardPoints);
            var geometry = new THREE.TubeGeometry(curve, 15, 0.002, 6, false);
            var material = new THREE.MeshBasicMaterial({
                color: 0xffff44,
                transparent: true,
                opacity: 0.7
            });
            
            var upwardFlow = new THREE.Mesh(geometry, material);
            eyeStructureGroup.add(upwardFlow);
        }
    };
    
    // 创建高质量粒子系统
    this.createParticles = function() {
        // 清空现有粒子
        while(particlesGroup.children.length > 0) {
            particlesGroup.remove(particlesGroup.children[0]);
        }
        particles = [];
        
        // 创建多种类型的高质量粒子
        this.createSpiralParticles();
        this.createEyeWallParticles();
        this.createOutflowParticles();
        this.createTurbulenceParticles();
        this.createTrailParticles();
        
        particlesGroup.visible = showParticles;
    };
    
    // 创建螺旋粒子 - 高质量实现
    this.createSpiralParticles = function() {
        var numParticles = 2000;
        
        for (var i = 0; i < numParticles; i++) {
            // 使用更精细的几何体
            var particleGeometry = new THREE.SphereGeometry(0.008, 8, 6);
            
            var radius = eyeRadius * 1.2 + Math.random() * 1.3;
            var windSpeedAtRadius = this.getWindSpeedAtRadius(radius);
            
            // 增强的颜色计算
            var colorIntensity = Math.min(windSpeedAtRadius / 2.5, 1.0);
            var color = this.getEnhancedParticleColor(colorIntensity, radius);
            
            // 使用发光材质增强视觉效果
            var material = new THREE.MeshBasicMaterial({
                color: color,
                transparent: true,
                opacity: 0.8 + colorIntensity * 0.2,
                emissive: color.clone().multiplyScalar(0.3)
            });
            
            var particle = new THREE.Mesh(particleGeometry, material);
            
            // 螺旋分布
            var spiralAngle = (i / numParticles) * Math.PI * 8 + Math.random() * Math.PI;
            var spiralRadius = radius + Math.sin(spiralAngle * 2) * 0.1;
            var height = Math.random() * flowHeight - 0.15;
            
            particle.position.set(
                Math.cos(spiralAngle) * spiralRadius,
                height,
                Math.sin(spiralAngle) * spiralRadius
            );
            
            // 添加粒子缩放变化
            var scale = 0.8 + Math.random() * 0.4;
            particle.scale.setScalar(scale);
            
            particlesGroup.add(particle);
            particles.push({
                mesh: particle,
                angle: spiralAngle,
                radius: spiralRadius,
                speed: windSpeedAtRadius * (0.4 + Math.random() * 0.6),
                verticalSpeed: (Math.random() - 0.5) * 0.08,
                originalRadius: radius,
                type: 'spiral',
                colorIntensity: colorIntensity,
                phase: Math.random() * Math.PI * 2,
                pulseFactor: 0.8 + Math.random() * 0.4,
                originalScale: scale
            });
        }
    };
    
    // 创建台风眼壁粒子 - 增强版
    this.createEyeWallParticles = function() {
        var numParticles = 500;
        
        for (var i = 0; i < numParticles; i++) {
            var particleGeometry = new THREE.SphereGeometry(0.006, 8, 6);
            var radius = eyeRadius * (0.9 + Math.random() * 0.3);
            
            // 台风眼壁的强烈颜色
            var intensity = 0.8 + Math.random() * 0.2;
            var color = new THREE.Color().setHSL(0.05 + Math.random() * 0.1, 0.95, 0.7);
            
            var material = new THREE.MeshBasicMaterial({
                color: color,
                transparent: true,
                opacity: 0.9,
                emissive: color.clone().multiplyScalar(0.4)
            });
            
            var particle = new THREE.Mesh(particleGeometry, material);
            
            var angle = Math.random() * Math.PI * 2;
            var height = Math.random() * flowHeight * 1.3 - 0.15;
            
            particle.position.set(
                Math.cos(angle) * radius,
                height,
                Math.sin(angle) * radius
            );
            
            // 添加随机缩放
            var scale = 1.2 + Math.random() * 0.6;
            particle.scale.setScalar(scale);
            
            particlesGroup.add(particle);
            particles.push({
                mesh: particle,
                angle: angle,
                radius: radius,
                speed: 2.5 + Math.random() * 1.5,
                verticalSpeed: 0.15 + Math.random() * 0.15,
                originalRadius: radius,
                type: 'eyewall',
                intensity: intensity,
                phase: Math.random() * Math.PI * 2,
                originalScale: scale
            });
        }
    };
    
    // 创建外流粒子 - 改进版
    this.createOutflowParticles = function() {
        var numParticles = 300;
        
        for (var i = 0; i < numParticles; i++) {
            var particleGeometry = new THREE.SphereGeometry(0.005, 6, 4);
            var radius = 1.3 + Math.random() * 0.6;
            
            var color = new THREE.Color().setHSL(0.55 + Math.random() * 0.1, 0.8, 0.6);
            
            var material = new THREE.MeshBasicMaterial({
                color: color,
                transparent: true,
                opacity: 0.7,
                emissive: color.clone().multiplyScalar(0.2)
            });
            
            var particle = new THREE.Mesh(particleGeometry, material);
            
            var angle = Math.random() * Math.PI * 2;
            var height = flowHeight * 0.9 + Math.random() * flowHeight * 0.3;
            
            particle.position.set(
                Math.cos(angle) * radius,
                height,
                Math.sin(angle) * radius
            );
            
            var scale = 0.6 + Math.random() * 0.4;
            particle.scale.setScalar(scale);
            
            particlesGroup.add(particle);
            particles.push({
                mesh: particle,
                angle: angle,
                radius: radius,
                speed: -(0.3 + Math.random() * 0.4),
                verticalSpeed: 0.03 + Math.random() * 0.04,
                originalRadius: radius,
                type: 'outflow',
                phase: Math.random() * Math.PI * 2,
                originalScale: scale
            });
        }
    };
    
    // 创建湍流粒子
    this.createTurbulenceParticles = function() {
        var numParticles = 400;
        
        for (var i = 0; i < numParticles; i++) {
            var particleGeometry = new THREE.SphereGeometry(0.004, 6, 4);
            var radius = eyeRadius * 0.5 + Math.random() * 2.0;
            
            var colorIntensity = Math.random();
            var color = this.getEnhancedParticleColor(colorIntensity, radius);
            
            var material = new THREE.MeshBasicMaterial({
                color: color,
                transparent: true,
                opacity: 0.6 + Math.random() * 0.3,
                emissive: color.clone().multiplyScalar(0.15)
            });
            
            var particle = new THREE.Mesh(particleGeometry, material);
            
            var angle = Math.random() * Math.PI * 2;
            var height = Math.random() * flowHeight - 0.1;
            
            particle.position.set(
                Math.cos(angle) * radius,
                height,
                Math.sin(angle) * radius
            );
            
            var scale = 0.5 + Math.random() * 0.5;
            particle.scale.setScalar(scale);
            
            particlesGroup.add(particle);
            particles.push({
                mesh: particle,
                angle: angle,
                radius: radius,
                speed: (Math.random() - 0.5) * 1.0,
                verticalSpeed: (Math.random() - 0.5) * 0.1,
                originalRadius: radius,
                type: 'turbulence',
                turbulencePhase: Math.random() * Math.PI * 2,
                turbulenceAmplitude: 0.1 + Math.random() * 0.2,
                originalScale: scale
            });
        }
    };
    
    // 创建尾迹粒子
    this.createTrailParticles = function() {
        var numParticles = 200;
        
        for (var i = 0; i < numParticles; i++) {
            var particleGeometry = new THREE.SphereGeometry(0.003, 4, 3);
            var radius = eyeRadius + Math.random() * 1.0;
            
            var color = new THREE.Color().setHSL(0.15 + Math.random() * 0.2, 0.7, 0.8);
            
            var material = new THREE.MeshBasicMaterial({
                color: color,
                transparent: true,
                opacity: 0.4 + Math.random() * 0.3,
                emissive: color.clone().multiplyScalar(0.1)
            });
            
            var particle = new THREE.Mesh(particleGeometry, material);
            
            var angle = Math.random() * Math.PI * 2;
            var height = Math.random() * flowHeight * 0.8 - 0.1;
            
            particle.position.set(
                Math.cos(angle) * radius,
                height,
                Math.sin(angle) * radius
            );
            
            var scale = 0.3 + Math.random() * 0.4;
            particle.scale.setScalar(scale);
            
            particlesGroup.add(particle);
            particles.push({
                mesh: particle,
                angle: angle,
                radius: radius,
                speed: 0.8 + Math.random() * 0.6,
                verticalSpeed: (Math.random() - 0.5) * 0.05,
                originalRadius: radius,
                type: 'trail',
                trailLength: 3 + Math.random() * 5,
                trailIndex: 0,
                originalScale: scale
            });
        }
    };
    
    // 获取增强的粒子颜色
    this.getEnhancedParticleColor = function(intensity, radius) {
        var distanceFromEye = Math.abs(radius - eyeRadius);
        var normalizedDistance = Math.min(distanceFromEye / 1.5, 1.0);
        
        var hue, saturation, lightness;
        
        if (intensity < 0.2) {
            // 深蓝色（低强度）
            hue = 0.65 - normalizedDistance * 0.1;
            saturation = 0.8;
            lightness = 0.4 + intensity * 1.5;
        } else if (intensity < 0.5) {
            // 蓝绿到绿色
            hue = 0.5 - (intensity - 0.2) * 0.5;
            saturation = 0.85;
            lightness = 0.5 + intensity * 0.3;
        } else if (intensity < 0.8) {
            // 绿到黄到橙
            hue = 0.25 - (intensity - 0.5) * 0.6;
            saturation = 0.9;
            lightness = 0.6 + intensity * 0.2;
        } else {
            // 橙到红（高强度）
            hue = 0.05 - (intensity - 0.8) * 0.05;
            saturation = 0.95;
            lightness = 0.7 + intensity * 0.1;
        }
        
        return new THREE.Color().setHSL(hue, saturation, lightness);
    };
    
    // 根据半径计算风速
     this.getWindSpeedAtRadius = function(radius) {
         if (radius < eyeRadius) {
             return 0.1; // 台风眼内风速很小
         } else if (radius < eyeRadius * 2) {
             // 台风眼壁区域风速最大
             return 2.0 * Math.sin((radius - eyeRadius) / eyeRadius * Math.PI / 2);
         } else {
             // 外围风速逐渐减小
             return 2.0 * Math.exp(-(radius - eyeRadius * 2) * 2);
         }
     };
     
     // 创建热力图
     this.createHeatmap = function() {
         // 清空现有热力图
         while(heatmapGroup.children.length > 0) {
             heatmapGroup.remove(heatmapGroup.children[0]);
         }
         
         // 创建热力图纹理
         var canvas = document.createElement('canvas');
         canvas.width = heatmapResolution;
         canvas.height = heatmapResolution;
         var ctx = canvas.getContext('2d');
         
         // 创建图像数据
         var imageData = ctx.createImageData(heatmapResolution, heatmapResolution);
         var data = imageData.data;
         
         // 生成热力图数据
         for (var y = 0; y < heatmapResolution; y++) {
             for (var x = 0; x < heatmapResolution; x++) {
                 var index = (y * heatmapResolution + x) * 4;
                 
                 // 将像素坐标转换为世界坐标
                 var worldX = (x / heatmapResolution - 0.5) * heatmapSize;
                 var worldZ = (y / heatmapResolution - 0.5) * heatmapSize;
                 var radius = Math.sqrt(worldX * worldX + worldZ * worldZ);
                 
                 // 计算该位置的风速强度
                 var windSpeed = this.getWindSpeedAtRadius(radius);
                 var intensity = Math.min(windSpeed / 2.0, 1.0);
                 
                 // 添加一些噪声以增加真实感
                 var noise = (Math.sin(worldX * 10) * Math.cos(worldZ * 10) + 1) * 0.5;
                 intensity = Math.max(0, Math.min(1, intensity + noise * 0.2 - 0.1));
                 
                 // 根据强度计算颜色 (绿色到红色渐变)
                 var r, g, b;
                 if (intensity < 0.5) {
                     // 绿色到黄色
                     r = Math.floor(intensity * 2 * 255);
                     g = 255;
                     b = 0;
                 } else {
                     // 黄色到红色
                     r = 255;
                     g = Math.floor((1 - intensity) * 2 * 255);
                     b = 0;
                 }
                 
                 // 设置像素颜色
                 data[index] = r;     // Red
                 data[index + 1] = g; // Green
                 data[index + 2] = b; // Blue
                 data[index + 3] = Math.floor(intensity * 180 + 50); // Alpha
             }
         }
         
         // 将图像数据绘制到画布
         ctx.putImageData(imageData, 0, 0);
         
         // 创建纹理
         var texture = new THREE.CanvasTexture(canvas);
         texture.needsUpdate = true;
         
         // 创建热力图几何体和材质
         var geometry = new THREE.PlaneGeometry(heatmapSize, heatmapSize, 1, 1);
         var material = new THREE.MeshBasicMaterial({
             map: texture,
             transparent: true,
             opacity: 0.7,
             side: THREE.DoubleSide
         });
         
         heatmapMesh = new THREE.Mesh(geometry, material);
         heatmapMesh.rotation.x = -Math.PI / 2; // 水平放置
         heatmapMesh.position.y = -0.25; // 稍微在地面之上
         
         heatmapGroup.add(heatmapMesh);
         heatmapGroup.visible = showHeatmap;
     };
     
     // 更新热力图
     this.updateHeatmap = function() {
         if (!heatmapMesh || !showHeatmap) return;
         
         // 添加动态效果 - 热力图的脉动
         var pulseFactor = Math.sin(time * 2) * 0.1 + 0.9;
         heatmapMesh.material.opacity = 0.7 * pulseFactor;
         
         // 轻微旋转以模拟台风的旋转
         heatmapMesh.rotation.z = time * windSpeed * 0.1;
     };
    
    // 获取增强的流线颜色
     this.getFlowLineColor = function(index, total) {
         // 根据流线位置计算颜色强度
         var normalizedIndex = index / total;
         var colorIntensity = Math.sin(normalizedIndex * Math.PI) * 0.8 + 0.2;
         
         // 创建从蓝绿色到橙红色的渐变
         var hue, saturation, lightness;
         
         if (colorIntensity < 0.3) {
             // 蓝色区域（外围低风速）
             hue = 0.6 + (0.3 - colorIntensity) * 0.1; // 蓝到青
             saturation = 0.7;
             lightness = 0.5 + colorIntensity * 0.3;
         } else if (colorIntensity < 0.7) {
             // 绿色到黄色区域（中等风速）
             hue = 0.33 - (colorIntensity - 0.3) * 0.25; // 绿到黄
             saturation = 0.8;
             lightness = 0.6;
         } else {
             // 橙色到红色区域（高风速）
             hue = 0.08 - (colorIntensity - 0.7) * 0.08; // 橙到红
             saturation = 0.9;
             lightness = 0.7;
         }
         
         return new THREE.Color().setHSL(hue, saturation, lightness);
     };
     
     // 获取基于风速的动态颜色
     this.getWindSpeedColor = function(windSpeed, maxWindSpeed) {
         var intensity = Math.min(windSpeed / maxWindSpeed, 1.0);
         
         var hue, saturation, lightness;
         
         if (intensity < 0.2) {
             // 深蓝色（很低风速）
             hue = 0.67;
             saturation = 0.8;
             lightness = 0.3 + intensity * 1.5;
         } else if (intensity < 0.4) {
             // 蓝绿色（低风速）
             hue = 0.5 + (0.4 - intensity) * 0.85;
             saturation = 0.7;
             lightness = 0.5;
         } else if (intensity < 0.6) {
             // 绿色到黄色（中等风速）
             hue = 0.33 - (intensity - 0.4) * 1.25;
             saturation = 0.8;
             lightness = 0.6;
         } else if (intensity < 0.8) {
             // 黄色到橙色（高风速）
             hue = 0.08 + (0.8 - intensity) * 0.25;
             saturation = 0.9;
             lightness = 0.7;
         } else {
             // 红色到深红色（极高风速）
             hue = 0.0;
             saturation = 0.95;
             lightness = 0.8 - (intensity - 0.8) * 1.5;
         }
         
         return new THREE.Color().setHSL(hue, saturation, lightness);
     };
    
    // 更新动画
    this.update = function(delta) {
        time += delta * animationSpeed;
        
        // 更新流线动画
        if (showFlowLines) {
            this.updateFlowLines();
        }
        
        // 更新台风眼动画
        if (showEyeStructure) {
            this.updateEyeStructure();
        }
        
        // 更新粒子动画
        if (showParticles) {
            this.updateParticles(delta);
        }
        
        // 更新热力图动画
        if (showHeatmap) {
            this.updateHeatmap();
        }
    };
    
    // 更新增强的流线动画
    this.updateFlowLines = function() {
        var self = this;
        
        // 更新主要螺旋流线
        flowLines.forEach(function(flowLine, index) {
            // 复杂的旋转动画
            flowLine.mesh.rotation.y = time * windSpeed + flowLine.phase;
            
            // 多层次脉动效果
            var pulseFactor1 = Math.sin(time * 2 + flowLine.phase) * 0.15 + 0.85;
            var pulseFactor2 = Math.sin(time * 5 + flowLine.phase * 2) * 0.1 + 0.9;
            var combinedPulse = pulseFactor1 * pulseFactor2;
            
            flowLine.mesh.material.opacity = opacity * combinedPulse;
            
            // 动态颜色变化
            var colorShift = Math.sin(time + flowLine.phase) * 0.1;
            var baseColor = self.getFlowLineColor(index, flowLines.length);
            var hsl = {};
            baseColor.getHSL(hsl);
            flowLine.mesh.material.color.setHSL(
                hsl.h + colorShift * 0.1,
                hsl.s,
                hsl.l + colorShift * 0.2
            );
        });
        
        // 更新所有流线组的动画
        this.updateFlowLinesGroup();
    };
    
    // 更新流线组动画
    this.updateFlowLinesGroup = function() {
        var children = flowLinesGroup.children;
        
        for (var i = 0; i < children.length; i++) {
            var child = children[i];
            
            // 根据流线类型应用不同的动画
            if (i < flowLines.length) {
                // 主要螺旋流线已在上面处理
                continue;
            } else if (i < flowLines.length + 12) {
                // 垂直流线动画
                var verticalIndex = i - flowLines.length;
                child.rotation.y = time * windSpeed * 0.5 + verticalIndex * 0.5;
                
                var verticalPulse = Math.sin(time * 3 + verticalIndex) * 0.2 + 0.8;
                child.material.opacity = opacity * 0.7 * verticalPulse;
            } else {
                // 多层次和径向流线动画
                var otherIndex = i - flowLines.length - 12;
                child.rotation.y = time * windSpeed * 0.3 + otherIndex * 0.2;
                
                var otherPulse = Math.sin(time * 4 + otherIndex * 0.5) * 0.15 + 0.85;
                child.material.opacity = child.material.opacity * otherPulse;
            }
        }
    };
    
    // 更新台风眼动画
    this.updateEyeStructure = function() {
        eyeStructureGroup.children.forEach(function(child, index) {
            if (index === 1) { // 漩涡
                child.rotation.z = time * windSpeed * 2;
            }
        });
    };
    
    // 更新增强粒子动画
    this.updateParticles = function(delta) {
        var self = this;
        particles.forEach(function(particle) {
            switch(particle.type) {
                case 'spiral':
                    self.updateSpiralParticle(particle, delta);
                    break;
                case 'eyewall':
                    self.updateEyeWallParticle(particle, delta);
                    break;
                case 'outflow':
                    self.updateOutflowParticle(particle, delta);
                    break;
                case 'turbulence':
                    self.updateTurbulenceParticle(particle, delta);
                    break;
                case 'trail':
                    self.updateTrailParticle(particle, delta);
                    break;
            }
            
            // 通用边界检查和重置
            self.checkParticleBounds(particle);
            
            // 动态颜色和透明度更新
            self.updateParticleVisuals(particle, delta);
        });
    };
    
    // 更新螺旋粒子
    this.updateSpiralParticle = function(particle, delta) {
        // 螺旋运动
        particle.angle += particle.speed * delta * windSpeed;
        
        // 添加径向振荡
        var radiusOscillation = Math.sin(time * 3 + particle.phase) * 0.05;
        var currentRadius = particle.originalRadius + radiusOscillation;
        
        // 计算新位置
        var x = Math.cos(particle.angle) * currentRadius;
        var z = Math.sin(particle.angle) * currentRadius;
        
        particle.mesh.position.x = x;
        particle.mesh.position.z = z;
        particle.mesh.position.y += particle.verticalSpeed * delta;
        
        // 动态缩放
        var scaleFactor = particle.originalScale * (1 + Math.sin(time * 4 + particle.phase) * 0.2);
        particle.mesh.scale.setScalar(scaleFactor);
    };
    
    // 更新湍流粒子
    this.updateTurbulenceParticle = function(particle, delta) {
        // 复杂的湍流运动
        particle.turbulencePhase += delta * 3;
        
        var turbulenceX = Math.sin(particle.turbulencePhase) * particle.turbulenceAmplitude;
        var turbulenceZ = Math.cos(particle.turbulencePhase * 1.3) * particle.turbulenceAmplitude;
        
        particle.angle += particle.speed * delta * windSpeed;
        
        var x = Math.cos(particle.angle) * particle.radius + turbulenceX;
        var z = Math.sin(particle.angle) * particle.radius + turbulenceZ;
        
        particle.mesh.position.x = x;
        particle.mesh.position.z = z;
        particle.mesh.position.y += particle.verticalSpeed * delta;
        
        // 随机缩放变化
        var randomScale = particle.originalScale * (1 + Math.sin(particle.turbulencePhase * 2) * 0.3);
        particle.mesh.scale.setScalar(randomScale);
    };
    
    // 更新尾迹粒子
    this.updateTrailParticle = function(particle, delta) {
        // 沿轨迹运动
        particle.angle += particle.speed * delta * windSpeed;
        
        var x = Math.cos(particle.angle) * particle.radius;
        var z = Math.sin(particle.angle) * particle.radius;
        
        particle.mesh.position.x = x;
        particle.mesh.position.z = z;
        particle.mesh.position.y += particle.verticalSpeed * delta;
        
        // 尾迹效果 - 逐渐消失
        particle.trailIndex += delta * 2;
        if (particle.trailIndex > particle.trailLength) {
            particle.trailIndex = 0;
        }
        
        var trailFactor = 1 - (particle.trailIndex / particle.trailLength);
        particle.mesh.material.opacity = 0.4 * trailFactor;
        particle.mesh.scale.setScalar(particle.originalScale * trailFactor);
    };
    
    // 检查粒子边界
    this.checkParticleBounds = function(particle) {
        // 垂直边界检查
        if (particle.mesh.position.y > flowHeight * 1.5) {
            particle.mesh.position.y = -0.3;
        }
        if (particle.mesh.position.y < -0.4) {
            particle.mesh.position.y = flowHeight * 1.2;
        }
        
        // 水平边界检查（对于某些类型的粒子）
        var distance = Math.sqrt(
            particle.mesh.position.x * particle.mesh.position.x + 
            particle.mesh.position.z * particle.mesh.position.z
        );
        
        if (distance > 3.0) {
            // 重置到台风中心附近
            var resetAngle = Math.random() * Math.PI * 2;
            var resetRadius = eyeRadius + Math.random() * 0.5;
            particle.mesh.position.x = Math.cos(resetAngle) * resetRadius;
            particle.mesh.position.z = Math.sin(resetAngle) * resetRadius;
            particle.angle = resetAngle;
            particle.radius = resetRadius;
        }
    };
    
    // 更新粒子视觉效果
    this.updateParticleVisuals = function(particle, delta) {
        // 动态颜色变化
        if (particle.type === 'spiral' || particle.type === 'turbulence') {
            var windSpeedAtPos = this.getWindSpeedAtRadius(particle.radius);
            var colorIntensity = Math.min(windSpeedAtPos / 2.5, 1.0);
            var newColor = this.getEnhancedParticleColor(colorIntensity, particle.radius);
            
            // 平滑颜色过渡
            particle.mesh.material.color.lerp(newColor, delta * 2);
            
            // 更新发光效果
            var emissiveColor = newColor.clone().multiplyScalar(0.2 + colorIntensity * 0.2);
            particle.mesh.material.emissive.lerp(emissiveColor, delta * 3);
        }
        
        // 基于时间的透明度脉动
        if (particle.pulseFactor) {
            var basePulse = Math.sin(time * 4 + particle.phase) * 0.1 + 0.9;
            var currentOpacity = particle.mesh.material.opacity;
            var targetOpacity = (0.8 + particle.colorIntensity * 0.2) * basePulse * particle.pulseFactor;
            particle.mesh.material.opacity = THREE.MathUtils.lerp(currentOpacity, targetOpacity, delta * 5);
        }
    };
    

    
    // 更新台风眼壁粒子
    this.updateEyeWallParticle = function(particle, delta) {
        // 快速旋转
        particle.angle += particle.speed * delta * windSpeed;
        
        // 强烈的上升运动
        particle.mesh.position.y += particle.verticalSpeed * delta;
        
        // 径向收缩效果
        var contractionFactor = 1 - Math.sin(time * 5 + particle.phase) * 0.1;
        var currentRadius = particle.radius * contractionFactor;
        
        var x = Math.cos(particle.angle) * currentRadius;
        var z = Math.sin(particle.angle) * currentRadius;
        
        particle.mesh.position.x = x;
        particle.mesh.position.z = z;
        
        // 强烈的脉动效果
        var pulseFactor = particle.originalScale * (1 + Math.sin(time * 8 + particle.phase) * 0.4);
        particle.mesh.scale.setScalar(pulseFactor);
    };
    
    // 更新外流粒子
    this.updateOutflowParticle = function(particle, delta) {
        // 向外扩散
        particle.radius += Math.abs(particle.speed) * delta;
        particle.angle += particle.speed * delta * windSpeed * 0.3;
        
        var x = Math.cos(particle.angle) * particle.radius;
        var z = Math.sin(particle.angle) * particle.radius;
        
        particle.mesh.position.x = x;
        particle.mesh.position.z = z;
        particle.mesh.position.y += particle.verticalSpeed * delta;
        
        // 随距离减小透明度
        var distanceFactor = Math.max(0, 1 - (particle.radius - particle.originalRadius) / 1.0);
        particle.mesh.material.opacity = 0.7 * distanceFactor;
        
        // 重置过远的粒子
        if (particle.radius > particle.originalRadius + 1.5) {
            particle.radius = particle.originalRadius;
            particle.mesh.material.opacity = 0.7;
        }
    };
    
    // 参数设置方法
    this.setWindSpeed = function(value) {
        windSpeed = value;
    };
    
    this.setEyeRadius = function(value) {
        eyeRadius = value;
        this.createFlowLines();
        this.createEyeStructure();
    };
    
    this.setSpiralTightness = function(value) {
        spiralTightness = value;
        this.createFlowLines();
    };
    
    this.setFlowHeight = function(value) {
        flowHeight = value;
        this.createFlowLines();
        this.createEyeStructure();
    };
    
    this.setAnimationSpeed = function(value) {
        animationSpeed = value;
    };
    
    this.setOpacity = function(value) {
        opacity = value;
        flowLines.forEach(function(flowLine) {
            flowLine.mesh.material.opacity = opacity;
        });
    };
    
    // 显示控制方法
    this.setFlowLinesVisible = function(visible) {
        showFlowLines = visible;
        flowLinesGroup.visible = visible;
    };
    
    this.setEyeStructureVisible = function(visible) {
        showEyeStructure = visible;
        eyeStructureGroup.visible = visible;
    };
    
    this.setParticlesVisible = function(visible) {
        showParticles = visible;
        particlesGroup.visible = visible;
    };
    
    this.setHeatmapVisible = function(visible) {
        showHeatmap = visible;
        heatmapGroup.visible = visible;
    };
    
    // 重新创建热力图（当参数改变时）
    this.recreateHeatmap = function() {
        if (showHeatmap) {
            this.createHeatmap();
        }
    };
};